<script setup lang="ts">
import { ref } from "vue";
import { useUserMgmt } from "./utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

// import Database from "@iconify-icons/ri/database-2-line";
// import More from "@iconify-icons/ep/more-filled";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import Refresh from "@iconify-icons/ep/refresh";
import Menu from "@iconify-icons/ep/menu";
import AddFill from "@iconify-icons/ri/add-circle-line";
import AddUserModal from "./add-user-modal.vue";
import RoleMgmtModal from "./role-mgmt-modal.vue";
import AddPermissionModal from "./add-permission.vue";
import { AgGridVue } from "ag-grid-vue3";

defineOptions({
  name: "SystemRole"
});

const formRef = ref();
const rowData = ref([
  { make: "Tesla", model: "Model Y", price: 64950, electric: true },
  { make: "Ford", model: "F-Series", price: 33850, electric: false },
  { make: "Toyota", model: "Corolla", price: 29600, electric: false }
]);

// Column Definitions: Defines the columns to be displayed.
const colDefs = ref([
  { field: "make", headerName: "接件时间", editable: true, pinned: "left" },
  { field: "model", headerName: "委托单位", editable: true },
  { field: "price", headerName: "业务联系人", editable: true },
  { field: "electric", headerName: "联系人电话", editable: true },
  { field: "electric", headerName: "联系人单位", editable: true },
  { field: "electric", headerName: "业务类型", editable: true },
  { field: "electric", headerName: "接受时送审金额", editable: true },
  {
    field: "electric",
    headerName: "接受时送审金额",
    cellRenderer: () => {
      return 1213;
      // return <> <el-button
      //           class="reset-margin"
      //           link
      //           type="primary"
      //           :size="size"
      //           :icon="useRenderIcon(EditPen)"
      //         >
      //           <!-- @click="openDialog('修改', row)" -->
      //           修改
      //         </el-button>
      //         <el-button
      //           class="reset-margin"
      //           link
      //           type="primary"
      //           :size="size"
      //           :icon="useRenderIcon(Menu)"
      //           @click="handleMenu"
      //         >
      //           菜单权限
      //         </el-button>
      //         <el-popconfirm
      //           :title="`是否确认删除角色名称为${row.name}的这条数据`"
      //           @confirm="handleDelete(row)"
      //         >
      //           <template #reference>
      //             <el-button
      //               class="reset-margin"
      //               link
      //               type="primary"
      //               :size="size"
      //               :icon="useRenderIcon(Delete)"
      //             >
      //               删除
      //             </el-button>
      //           </template>
      //         </el-popconfirm></>
    }
  }
]);
const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  // buttonClass,
  onSearch,
  resetForm,
  handleMenu,
  handleDelete,
  // handleDatabase,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  openAddPermissionModal,
  addUserModalRef,
  roleMgmtModalRef,
  addPermissionModalRef,
  openAddUserModal,
  openAddRoleModal
} = useUserMgmt();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-form-item label="用户名：" prop="name">
        <el-input
          v-model="form.name"
          placeholder="请输入用户名："
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-button
        type="primary"
        :icon="useRenderIcon(AddFill)"
        @click="openAddUserModal"
      >
        新增用户
      </el-button>
      <el-button
        type="primary"
        :icon="useRenderIcon(AddFill)"
        @click="openAddRoleModal"
      >
        新增角色
      </el-button>
      <el-button
        type="primary"
        :icon="useRenderIcon(AddFill)"
        @click="openAddPermissionModal"
      >
        新增权限
      </el-button>
    </div>
    <ag-grid-vue
      :rowData="rowData"
      :columnDefs="colDefs"
      style="height: 400px"
      :enableRangeSelection="true"
      :enableFillHandle="true"
      :fillHandleDirection="'xy'"
      :rowSelection="{
        mode: 'multiRow'
      }"
    ></ag-grid-vue>
    <AddUserModal ref="addUserModalRef" />
    <RoleMgmtModal ref="roleMgmtModalRef" />
    <AddPermissionModal ref="addPermissionModalRef" />
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>
